package system.track;

/**
 * This provides special behavior for block 9.
 *
 * This is because in the clockwise direction there is
 * no switch, so get next block needs to be overridden to
 * provide block 8 directly.  Also, the getters and setters
 * for the switches need to handle this special case.
 *
 * @author David Kolb
 */
public class Block9 extends Block
{
    private Block cwBlock;

    public Block9()
    {
        super(9);
    }

    public void setCWBlock(Block cwBlock)
    {
        this.cwBlock = cwBlock;
    }

    @Override
    public Switch getSwitch(Direction d)
    {
        Switch returnVal = null;
        if (d != Direction.CLOCKWISE)
        {
            returnVal = super.getSwitch(d);
        }
        return returnVal;
    }

    @Override
    public void setSwitch(Direction d, Switch s)
    {
        if (d != Direction.CLOCKWISE)
        {
            super.setSwitch(d, s);
        }
    }

    @Override
    public Block getNextBlock(Direction d)
    {
        Block returnVal = this.cwBlock;
        if (d != Direction.CLOCKWISE)
        {
            returnVal = super.getNextBlock(d);
        }
        return returnVal;
    }

    @Override
    public Block getSpecificBlock(Direction d, SwitchAngle a)
    {
        Block returnVal = this.cwBlock;
        if (d != Direction.CLOCKWISE)
        {
            returnVal = super.getSpecificBlock(d, a);
        }
        return returnVal;
    }

    @Override
    public synchronized void autoSetSwitch(Direction d)
    {
        if (d != Direction.CLOCKWISE)
        {
            super.autoSetSwitch(d);
        }
    }
}
